
const tokens = {
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  }
}

// const users = {
//   'admin-token': {
//     roles: ['admin'],
//     introduction: 'I am a super administrator',
//     avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
//     name: 'Super Admin'
//   },
//   'editor-token': {
//     roles: ['editor'],
//     introduction: 'I am an editor',
//     avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
//     name: 'Normal Editor'
//   }
// }

export default [
  // user login
  {
    url: '/auth/login',
    type: 'post',
    response: config => {
      const { username } = config.body
      const token = tokens[username]
      // mock error
      if (!token) {
        return {
          code: 60204,
          message: '账号或密码不正确'
        }
      }

      return {
        code: 20000,
        data: token
      }
    }
  },

  // get user info
  {
    url: '/user/info\.*',
    type: 'post',
    response: config => {
      const info = {
        roles: ['admin'],
        introduction: 'I am a super administrator',
        avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
        name: 'Super Admin'
      }
      // mock error
      if (!info) {
        return {
          code: 50008,
          message: 'Login failed, unable to get user details.'
        }
      }

      return {
        code: 20000,
        data: info
      }
    }
  },

  {
    url: '/user/permission',
    type: 'post',
    response: config => {
      const info = {
        'routerJson': [
          {
            'path': '',
            'component': 'Layout',
            'redirect': 'dashboard',
            'children': [
              {
                'path': 'dashboard',
                'component': 'dashboard/index',
                'meta': {
                  'title': '首页',
                  'icon': 'dashboard'
                }
              }
            ]
          },
          {
            'path': '/example',
            'component': 'Layout',
            'redirect': '/example/table',
            'name': 'Example',
            'meta': {
              'title': '案例',
              'icon': 'example'
            },
            'children': [
              {
                'path': 'table',
                'name': 'Table',
                'component': 'table/index',
                'meta': {
                  'title': '表格',
                  'icon': 'table'
                }
              },
              {
                'path': 'tree',
                'name': 'Tree',
                'component': 'tree/index',
                'meta': {
                  'title': '树形菜单',
                  'icon': 'tree'
                }
              }
            ]
          },
          {
            'path': '/form',
            'component': 'Layout',
            'children': [
              {
                'path': 'list.vue',
                'name': 'Form',
                'component': 'form/index',
                'meta': {
                  'title': '表单',
                  'icon': 'form'
                }
              }
            ]
          },
          {
            'path': '*',
            'redirect': '/404',
            'hidden': true
          }
        ]
      }
      // mock error
      if (!info) {
        return {
          code: 50008,
          message: 'Login failed, unable to get user details.'
        }
      }

      return {
        code: 20000,
        data: info
      }
    }
  },

  // user logout
  {
    url: '/auth/logout',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]
